//
//  ISPRootController.m
//  isou_pad
//
//  Created by wangneihan on 16/4/25.
//  Copyright © 2016年 isou. All rights reserved.
//

#import "ISPRootController.h"
#import "ISPTabBarButton.h"
#import "ISPHomeController.h"
#import "ISPInspirationController.h"
#import "ISPPersonalController.h"
#import "ISPProductController.h"
#import "ISPTabBar.h"

@interface ISPRootController ()

@property (nonatomic,strong) NSMutableArray *item;

@end

@implementation ISPRootController

-(NSMutableArray *)item
{
    if (_item == nil) {
        _item = [NSMutableArray array];
    }
    return _item;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self AddControlls];
    ISPTabBar *tabBar = [[ISPTabBar alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 49, 0,49,[UIScreen mainScreen].bounds.size.height)];
    [tabBar setBackgroundColor:[UIColor whiteColor]];
    tabBar.btnItems = self.item;
    _tabBar = tabBar;
}

-(void)AddControlls
{
    //1. Home
//    ISPHomeController *homeController = [[ISPHomeController alloc]init];
//    [self makeSubControl:homeController title:@"首页" Img:[UIImage imageNamed:@"tabbar_home"] tag:0 selectImg:[UIImage imageNamed:@"tabbar_home_selected"]];
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"ISZSHome" bundle:nil];
    ISPHomeController *homeC = [sb instantiateViewControllerWithIdentifier:@"ISPHomeControllerKey"];
    [self makeSubControl:homeC title:@"首页" Img:[UIImage imageNamed:@"tabbar_home"] tag:0 selectImg:[UIImage imageNamed:@"tabbar_home_selected"]];
    
    ISPInspirationController *inspirationController = [[ISPInspirationController alloc]init];
    [self makeSubControl:inspirationController title:@"灵感" Img:[UIImage imageNamed:@"tabbar_discover"] tag:1 selectImg:[UIImage imageNamed:@"tabbar_discover_selected"]];
    
    ISPProductController *productController = [[ISPProductController alloc]init];
    [self makeSubControl:productController title:@"产品" Img:[UIImage imageNamed:@"tabbar_message_center"] tag:2 selectImg:[UIImage imageNamed:@"tabbar_message_center_selected"]];
    
    ISPPersonalController *personalController = [[ISPPersonalController alloc]init];
    [self makeSubControl:personalController title:@"我" Img:[UIImage imageNamed:@"tabbar_profile"] tag:3 selectImg:[UIImage imageNamed:@"tabbar_profile_selected"]];
    
}

-(void)makeSubControl:(UIViewController *)controller  title:(NSString *)title Img:(UIImage *)image tag:(NSInteger) tag selectImg:(UIImage *)selectImg
{
    ISPTabBarButton *tabBarBtn = [[ISPTabBarButton alloc]init];
    tabBarBtn.controller = controller;
    
    [tabBarBtn setTitle:title forState:UIControlStateNormal];
    [tabBarBtn setImage:image forState:UIControlStateNormal];
    [tabBarBtn setImage:selectImg forState:UIControlStateSelected];
    tabBarBtn.tag = tag;
    
    [tabBarBtn addTarget:tabBarBtn action:@selector(tabBarBtnClick:) forControlEvents:UIControlEventAllTouchEvents];
    
    UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:controller];
    [self addChildViewController:navC];
    
    [self.item addObject:tabBarBtn];
}

-(void)selectTabBarBtn:(NSInteger) index
{
    for(UIButton *btn in self.tabBar.btnItems) {
        if(btn.tag == index)
            [btn setSelected:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)prefersStatusBarHidden
{
    return  YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
